<template>
	<view class="cart-container">
    <my-address></my-address>
		<!-- 购物车标题区域 -->
    <view class="cart-title">
      <!-- 左侧小图标 -->
      <uni-icons type="cart" size="18"></uni-icons>
      <!-- 右侧文档 -->
      <view class="cart-title-text">购物车</view>
    </view>
    <!-- 商品列表区域 -->
    <uni-swipe-action>
      <block v-for="(goods, i) in cart" :key='i'>
        <uni-swipe-action-item :options="options" @click="swipeActionClickHandler(goods)">
          <my-goods 
            :goods="goods" 
            :show-radio='true' 
            :show-number="true" 
            @change-radio='changeRadioHandler' 
            @change-num='numberChangeHandler'>
          </my-goods>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    <!-- 结算区域 -->
    <my-settle></my-settle>
	</view>
</template>

<script>
  import badagMix from '@/mixins/minix.js'
  // 导入mapSdata这个辅助函数
  import { mapState, mapMutations } from 'vuex'
	export default {
    mixins:[badagMix],
    computed:{
      ...mapState('m_cart', ['cart'])
    },
		data() {
			return { 
      options: [{
        text: '删除', // 显示的文本内容
        style: {
          backgroundColor: '#C00000' // 按钮的背景颜色
          }
        }]
      };
		},
    methods:{
      ...mapMutations('m_cart', ['updataCartState', 'updataCartCount'],),
      changeRadioHandler(e) {
        // console.log(e)
        this.updataCartState(e)
      },
      numberChangeHandler(e){
        this.updataCartCount(e)
      },
      // 点击了滑动操作按钮
      swipeActionClickHandler(goods) {
        console.log(goods)
      }
    }
	}
</script>

<style lang="scss">
.cart-title{
  height: 40px;
  display: flex;
  padding-left: 5px;
  align-items: center;
  font-size: 14px;
  border-bottom: 1px solid #EFEFEF;
  .cart-title-text{
    margin-left: 10px;
  }
}
.cart-container{
  padding-bottom: 50px;
}
</style>
